package com.cjk.console.ctrl;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.cjk.console.SessionApi;
import com.cjk.console.request.AdRequest;
import com.cjk.console.service.AdService;
import com.cjk.foundation.commons.response.Response;

@Controller
@RequestMapping("/ad")
public class AdController {
	
	@Autowired
	private AdService adService;
	
	@RequestMapping(value = "/getAdList.do", method = RequestMethod.POST)
	@ResponseBody
	public Response getAdList(@RequestBody AdRequest request, HttpSession session) {
		final Integer userId = SessionApi.getLoginUserId(session);
		return adService.getAdList(userId, request);
	}
	
	@RequestMapping(value = "/delAd.do", method = RequestMethod.POST)
	@ResponseBody
	public Response delAd(@RequestBody AdRequest request, HttpSession session) {
		final Integer userId = SessionApi.getLoginUserId(session);
		return adService.delAd(request, userId);
	}
	
	@RequestMapping(value = "/writeHotelServiceJson.do", method = RequestMethod.POST)
	@ResponseBody
	public Response writeHotelServiceJson(@RequestBody AdRequest request, HttpSession session) {
		final Integer userId = SessionApi.getLoginUserId(session);
		return adService.writeHotelServiceJson(request, userId);
	}
	
	@RequestMapping(value = "/getAdConf.do", method = RequestMethod.POST)
	@ResponseBody
	public Response getAdConf(Integer groupId, HttpSession session) {
		final Integer userId = SessionApi.getLoginUserId(session);
		return adService.getHotelServiceJson(groupId, userId);
	}
	
	@RequestMapping(value = "/confAd.do", method = RequestMethod.POST)
	@ResponseBody
	public Response confAd(@RequestBody AdRequest request, HttpSession session) {
		final Integer userId = SessionApi.getLoginUserId(session);
		return adService.confAd(request.getGroupId(), userId);
	}
}
